<?php

namespace app\admin\controller;

class AgencyCooperation extends Backend
{
    protected $model = null;

    protected $beforeActionList = [
        'notfound' => ['only' => 'add,edit,save,delete'],
    ];

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\admin\model\AgencyCooperation();
    }

    public function config()
    {
        $agencyConfigModel = new \app\admin\model\AgencyCooperationContent();
        $params = $this->request->param();
        $list = $agencyConfigModel->select();
        if ($this->request->isPost()) {
            if (sizeof($list) > 0) {
                $params['id'] = $list[0]['id'];
                $result = $agencyConfigModel->isUpdate(true, ['id' => $params['id']])->save($params);
                $this->success('保存成功');
            } else {
                $params['create_time'] = time();
                unset($params['id']);
                $result = $agencyConfigModel->save($params);
                if ($result) {
                    $this->success('保存成功');
                } else {
                    $this->error('保存失败');
                }
            }
        }
        $this->assign('row', sizeof($list) > 0 ? $list[0] : []);
        return $this->fetch();
    }

}